FROM node:14.16.1
ENV LANG C.UTF-8

COPY ./frontend /app/frontend
WORKDIR /app/frontend
RUN npm config set registry https://registry.npm.taobao.org/
RUN npm i node-sass --sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
RUN npm install
RUN npm run build

# 字体文件，解决报告无法显示中文问题
COPY Noto_Sans_SC.zip /tmp
RUN sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list && \
    apt update && \
    apt-get install -y dpkg wget unzip
RUN cd /tmp && wget http://ftp.cn.debian.org/debian/pool/main/f/fonts-noto-cjk/fonts-noto-cjk_20170601+repack1-3+deb10u1_all.deb && \
    dpkg -i fonts-noto-cjk_20170601+repack1-3+deb10u1_all.deb && \
    unzip Noto_Sans_SC.zip  && mv ./Noto_Sans_SC /usr/share/fonts/  && \
    fc-cache -f -v

# 解决Linux机器 puppeteer 所依赖的 Chromium 缺少所需要的依赖项 https://github.com/puppeteer/puppeteer/blob/v3.0.1/.ci/node12/Dockerfile.linux#L3-L9
RUN apt-get update && \
  apt-get -y install xvfb gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 \
    libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 \
    libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 \
    libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 \
    libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget && \
  rm -rf /var/lib/apt/lists/*

COPY ./backend /app/backend
WORKDIR /app/backend
VOLUME /app/carbonReport
RUN cp -r /app/frontend/dist /app/backend
RUN npm install
EXPOSE 3000
CMD npm start
